{% extends 'base.html' %}

{% block title %}
管理中心
{% endblock %}

{% block content %}
<div class="container mt-5">
    <h2 class="text-center mb-4">管理中心</h2>

    <div class="mb-5">
        <h3>赛事管理</h3>
        <a href="{{ url_for('add_event') }}" class="btn btn-success mb-3">添加赛事</a>
        <table class="table table-bordered table-hover">
            <thead class="table-dark">
                <tr>
                    <th>ID</th>
                    <th>赛事名称</th>
                    <th>描述</th>
                    <th>每日配额</th>
                    <th>截止时间</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {% for event in events %}
                <tr>
                    <td>{{ event.id }}</td>
                    <td>{{ event.name }}</td>
                    <td>{{ event.description }}</td>
                    <td>{{ event.quota }}</td>
                    <td>{{ event.end_time.strftime('%Y-%m-%d') }}</td>
                    <td>
                        <a href="{{ url_for('edit_event', event_id=event.id) }}" class="btn btn-primary btn-sm">编辑</a>
                        <a href="{{ url_for('manage_event_quotas', event_id=event.id) }}" class="btn btn-info btn-sm">管理配额</a>
                        <a href="{{ url_for('delete_event', event_id=event.id) }}" class="btn btn-danger btn-sm" onclick="return confirm('确定要删除吗？')">删除</a>
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>

    <div>
        <div class="d-flex justify-content-between align-items-center mb-3">
            <h3>预约记录</h3>
            <a href="{{ url_for('download_bookings') }}" class="btn btn-primary">
                <i class="bi bi-download"></i> 下载Excel
            </a>
        </div>
        <table class="table table-bordered table-hover">
            <thead class="table-dark">
                <tr>
                    <th>订单号</th>
                    <th>赛事名称</th>
                    <th>预约人</th>
                    <th>手机号</th>
                    <th>证件类型</th>
                    <th>证件号码</th>
                    <th>预约日期</th>
                    <th>预约时间</th>
                    <th>状态</th>
                    <th>核销时间</th>
                </tr>
            </thead>
            <tbody>
                {% for booking in bookings %}
                <tr>
                    <td>{{ booking.order_number }}</td>
                    <td>{{ booking.event.name }}</td>
                    <td>{{ booking.name }}</td>
                    <td>{{ booking.phone }}</td>
                    <td>{{ booking.id_type }}</td>
                    <td>{{ booking.id_number }}</td>
                    <td>{{ booking.booking_date.strftime('%Y-%m-%d') }}</td>
                    <td>{{ booking.created_at.strftime('%Y-%m-%d %H:%M:%S') }}</td>
                    <td>{{ '有效' if booking.is_valid else '已核销' }}</td>
                    <td>{{ booking.verified_at.strftime('%Y-%m-%d %H:%M:%S') if booking.verified_at else '-' }}</td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
</div>
{% endblock %}